<?php
/**
 * Created by PhpStorm.
 * User: yangliu
 * Date: 2019-01-09
 * Time: 11:03
 */

namespace app\common\model\order;

use think\Db;
use think\Model;

/**
 * 地区数据模型
 */
class Orderitem extends Model
{
    protected $name = 'order_item';

    protected $append = [
        'status_text',
        'preproductimg_text',
        'preproductname_text',
    ];

    public function getStatusList()
    {
        return [0=>'待发货',1=>'已发货'];
    }

    public function getPreproductnameList()
    {
        $list = \think\Cache::get('preproduct_attribute');
        return array_column($list,'cname','id');
    }

    public function getPreproductimgList()
    {
        $list = Db::table('hdyj_preproduct')->cache('preproduct_attribute',600)->field('id,cname,image')->select();
        return array_column($list,'image','id');
    }

    public function getPreproductnameTextAttr($value, $data)
    {
        $value = $value ? $value : $data['preproduct_id'];
        $list = $this->getPreproductnameList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getPreproductimgTextAttr($value, $data)
    {
        $value = $value ? $value : $data['preproduct_id'];
        $list = $this->getPreproductimgList();
        return imgno($list[$value]);
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

}
